let {jwtService} = require('../service/jwtService.js');
let config = require('../config.js');

let checkTokenMiddleware = async (request, response, next) => {
    let token = request.headers['authorization'];
    if (!token) {
        return response.error(config.result.tokenExpire)
    } else {
        let res = jwtService.verify(token);
        if (res) {
            request.userinfo = res;
            next();
        } else {
            return response.error(config.result.tokenExpire)
        }
    }
}

exports.checkTokenMiddleware = checkTokenMiddleware
